package com.diy.sigmund.diyuser.controller;

import com.diy.sigmund.diycommon.entity.enumerate.VerifyParamPolicyEnum;
import com.diy.sigmund.diycommon.spring.anno.IgnoreTokenVerification;
import com.diy.sigmund.diycommon.spring.anno.VerifyParam;
import com.diy.sigmund.diycommon.spring.anno.VerifyParams;
import com.diy.sigmund.diyuser.entity.dto.UserAuthDTO;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ylm-sigmund
 * @since 2021/8/17 12:04
 */
@RestController
@RequestMapping("/user/springOrder")
public class SpringOrderTestController {

    private static final Logger log = LoggerFactory.getLogger(SpringOrderTestController.class);

    @IgnoreTokenVerification
    @PostMapping("/test")
    @Transactional
    @Async
    // @Async("customAsyncExecutor")
    @VerifyParams(value = @VerifyParam(fieldName = "credential", verifyPolicy = VerifyParamPolicyEnum.NOT_BLANK, msg = "密码不能为空"))
    public void test(@RequestBody UserAuthDTO dto) throws InterruptedException {
        log.info("我进入了测试方法");
        TimeUnit.SECONDS.sleep(2);
        log.info("该方法中存在事务={},getCurrentTransactionName={},getCurrentTransactionIsolationLevel={}",
                TransactionSynchronizationManager.isActualTransactionActive(),
                TransactionSynchronizationManager.getCurrentTransactionName(),
                TransactionSynchronizationManager.getCurrentTransactionIsolationLevel());
        log.info("hello");
        TimeUnit.SECONDS.sleep(2);
        // return new AsyncResult<>(ResultMsg.success());
    }
}
